package exercise.iotest;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;

public class ClientTest {

    private static final int PORT =  15151;
    
    public static void main(String[] args) throws UnknownHostException, IOException {
        
        Socket socket = new Socket("127.0.0.1",PORT);
        OutputStream os = socket.getOutputStream();
        PrintWriter pw = new PrintWriter(os);
        pw.write("用户名：gaoyue；密码：123321");
        pw.flush();
        socket.shutdownOutput();
        InputStream is = socket.getInputStream();
        InputStreamReader isr = new InputStreamReader(is, "utf8");
        BufferedReader br = new BufferedReader(isr);
        String info;
        while((info = br.readLine())!=null){
            System.out.println("我是客户端，服务器说："+info);
        }
        br.close();
        isr.close();
        pw.close();
        os.close();
        socket.close();
        
    }

}
